/******************************************************************************
	This file is a part of the Snapshot Bioinformatics Project

	Copyright (C) 2012-2013 Jarom Schow

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/

#include "ConnectDlg.h"

#include <QtGui/QGridLayout>
#include <QtGui/QLabel>
#include <QtGui/QLineEdit>
#include <QtGui/QPushButton>
#include <QtGui/QComboBox>

#include "ConnectFrame.h"

const int	c_postgreDefaultPort = 5432;
const int	c_mySqlDefaultPort = 3306;

/**
**/
ConnectDlg::ConnectDlg( QWidget *parent, const QString &host, int port, const QString &user,
		const QString &pass, const QString &dbName, Bio::SqlServer::ServerType type, bool create ) : QDialog( parent )
{
	if( create )
		setWindowTitle( tr( "Create a new BioSQL Database" ) );
	else
		setWindowTitle( tr( "Connect to a BioSQL Database" ) );

	initLayout( host, port, user, pass, dbName, type, create );
}

/**
**/
ConnectDlg::~ConnectDlg()
{
}

/**
**/
void ConnectDlg::accept()
{
	QDialog::accept();
}

/**
**/
Bio::SqlServer::ServerType ConnectDlg::getServerType() const
{
	return m_frame->getServerType();
}

/**
**/
QString ConnectDlg::getHost() const
{
	return m_frame->getHost();
}

/**
**/
int ConnectDlg::getPort() const
{
	return m_frame->getPort();
}

/**
**/
QString ConnectDlg::getUser() const
{
	return m_frame->getUser();
}

/**
**/
QString ConnectDlg::getPassword() const
{
	return m_frame->getPassword();
}

/**
**/
QString ConnectDlg::getDBName() const
{
	return m_frame->getDBName();
}

/**
**/
void ConnectDlg::initLayout( const QString &host, int port, const QString &user, const QString &pass,
						const QString &dbName, Bio::SqlServer::ServerType type, bool create )
{
	QPushButton	*btn;
	QVBoxLayout	*layout = new QVBoxLayout;

	setLayout( layout );

	m_frame = new ConnectFrame( this, host, port, user, pass, dbName, type );
	layout->addWidget( m_frame );

	QHBoxLayout	*btnLayout = new QHBoxLayout;

	layout->addLayout( btnLayout );

	btnLayout->setMargin( 0 );
	btnLayout->addStretch( 100 );

	if( create )
		btn = new QPushButton( tr( "Create" ), this );
	else
		btn = new QPushButton( tr( "Connect" ), this );
	connect( btn, SIGNAL(clicked()), this, SLOT(accept()) );
	btnLayout->addWidget( btn );

	btn = new QPushButton( tr( "Cancel" ), this );
	connect( btn, SIGNAL(clicked()), this, SLOT(reject()) );
	btnLayout->addWidget( btn );
}

